package com.augurit.common.system.service.index.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.augurit.common.base.extmodel.ExtStoreMenu;
import com.augurit.common.base.extmodel.base.ExtElement;
import com.augurit.common.base.extmodel.base.LinkTreeNode;
import com.augurit.common.constant.OrgConstant;
import com.augurit.common.dao.AcApplicationDao;
import com.augurit.common.dao.AcFunctionDao;
import com.augurit.common.dao.AcMenuDao;
import com.augurit.common.dao.AcModuleDao;
import com.augurit.common.dao.AcRoleDao;
import com.augurit.common.dao.AcRoleFuncDao;
import com.augurit.common.dao.AcUserRoleDao;
import com.augurit.common.dao.AtHomepageConfigDao;
import com.augurit.common.dao.OmUserDao;
import com.augurit.common.dao.SysCodeItemDao;
import com.augurit.common.dao.SysCodeTypeDao;
import com.augurit.common.dao.SysConfigDao;
import com.augurit.common.dao.SysFileDao;
import com.augurit.common.entity.AcApplication;
import com.augurit.common.entity.AcFunction;
import com.augurit.common.entity.AcMenu;
import com.augurit.common.entity.AcModule;
import com.augurit.common.entity.AcRole;
import com.augurit.common.entity.AcRoleFunc;
import com.augurit.common.entity.AcUserRole;
import com.augurit.common.entity.AtHomepageConfig;
import com.augurit.common.entity.OmUser;
import com.augurit.common.entity.SysCodeItem;
import com.augurit.common.entity.SysCodeType;
import com.augurit.common.entity.SysConfig;
import com.augurit.common.system.service.index.IInitConfigService;
import com.augurit.common.system.util.WebContextUtils;

/**
 * 后台系统管理初始化配置逻辑实现类
 */
@Service
@Transactional
public class InitConfigServiceImpl implements IInitConfigService {
	
	@Autowired
	private SysConfigDao sysConfigDao;
	
	@Autowired
	private AcRoleDao acRoleDao;
	
	@Autowired
	private OmUserDao omUserDao;
	
	@Autowired
	private AcApplicationDao acApplicationDao;
	
	@Autowired
	private AcModuleDao acModuleDao;
	
	@Autowired
	private AcFunctionDao acFunctionDao;
	
	@Autowired
	private AcUserRoleDao acUserRoleDao;
	
	@Autowired
	private AcMenuDao acMenuDao;
	
	@Autowired
	private AcRoleFuncDao acRoleFuncDao;
	
	@Autowired
	private AtHomepageConfigDao atHomepageConfigDao;
	
	@Autowired
	private SysCodeTypeDao sysCodeTypeDao;
	
	@Autowired
	private SysCodeItemDao sysCodeItemDao;

	
	/**
	 * 执行系统管理初始化数据操作
	 * @param aosAdminPassword 系统管理员密码
	 */
	public void initConfig(String aosAdminPassword){
		
		//添加系统初始化配置参数
		addSysConfig();
		
		//添加若干系统首页配置信息
		this.addHomepageConfig();
		
		//添加必要的数据字典项
		this.addSysCode();
		
		
		
		//添加系统管理员角色
		Long roleId = this.addAosAdminRole();
		
		//添加系统管理员用户
		Long userId = this.addAosAdminUser(aosAdminPassword);
		
		//用户与角色关联
		this.addUserRole(userId, roleId);
		
		//添加应用
		AcApplication app = this.addLocalApp();
		
		//添加模块和功能
		AcModule orgMgmModule = this.addOrgMgmModule(app.getAppId());
		AcFunction orgUserMgmFunc = this.addOrgUserMgmFunc(orgMgmModule.getModuleId());
		AcFunction groupMgmFunc = this.addGroupMgmFunc(orgMgmModule.getModuleId());
		
		AcModule privMgmModule = this.addPrivMgmModule(app.getAppId());
		AcFunction appMgmFunc = this.addAppMgmFunc(privMgmModule.getModuleId());
		AcFunction menuMgmFunc = this.addMenuMgmFunc(privMgmModule.getModuleId());
		AcFunction roleMgmFunc = this.addRoleMgmFunc(privMgmModule.getModuleId());
		
		AcModule otherMgmModule = this.addOtherMgmModule(app.getAppId());
		AcFunction sysCodeMgmFunc = this.addSysCodeMgmFunc(otherMgmModule.getModuleId());
		AcFunction webServerMgmFunc = this.addWebServerMgmFunc(otherMgmModule.getModuleId());
		AcFunction homepageMgmFunc = this.addHomepageMgmFunc(otherMgmModule.getModuleId());
		AcFunction customShortcutFunc = this.addCustomShortcutFunc(otherMgmModule.getModuleId());
		AcFunction shortcutMgmFunc = this.addShortcutMgmFunc(otherMgmModule.getModuleId());
		AcFunction sysConfigFunc = this.addSysConfigFunc(otherMgmModule.getModuleId());
		AcFunction sysFileFunc = this.addSysFileMgmtFunc(otherMgmModule.getModuleId());
		AcFunction systemTraceLogFunc = this.addSystemTraceLogFunc(otherMgmModule.getModuleId());
		AcFunction sysLoginLogFunc = this.addSysLoginLogFunc(otherMgmModule.getModuleId());
		AcFunction sysPropAuditLogFunc = this.addSysPropAuditLogFunc(otherMgmModule.getModuleId());
		AcFunction regularWorkTimeMgmtFunc = this.addRegularWorkTimeMgmtFunc(otherMgmModule.getModuleId());
		AcFunction specialTimeMgmtFunc = this.addSpecialTimeMgmtFunc(otherMgmModule.getModuleId());
		AcFunction aosLinkFunc = this.addAosLinkFunc(otherMgmModule.getModuleId());
		
		//添加角色功能关联
		this.addRoleFunc(roleId, orgUserMgmFunc.getFuncId(), orgUserMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, groupMgmFunc.getFuncId(), groupMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, appMgmFunc.getFuncId(), appMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, menuMgmFunc.getFuncId(), menuMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, roleMgmFunc.getFuncId(), roleMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, sysCodeMgmFunc.getFuncId(), sysCodeMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, webServerMgmFunc.getFuncId(), webServerMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, homepageMgmFunc.getFuncId(), homepageMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, customShortcutFunc.getFuncId(), customShortcutFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, shortcutMgmFunc.getFuncId(), shortcutMgmFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, sysConfigFunc.getFuncId(), sysConfigFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, sysFileFunc.getFuncId(), sysFileFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, systemTraceLogFunc.getFuncId(), systemTraceLogFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, sysLoginLogFunc.getFuncId(), sysLoginLogFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, sysPropAuditLogFunc.getFuncId(), sysPropAuditLogFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, regularWorkTimeMgmtFunc.getFuncId(), regularWorkTimeMgmtFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, specialTimeMgmtFunc.getFuncId(), specialTimeMgmtFunc.getModuleId(), app.getAppId());
		this.addRoleFunc(roleId, aosLinkFunc.getFuncId(), aosLinkFunc.getModuleId(), app.getAppId());
		
		//添加菜单
		AcMenu sysMgmMenu = this.addSysMgmMenu(app.getAppId());
		
		AcMenu orgMgmMenu = this.addOrgMgmMenu(app.getAppId(), sysMgmMenu.getMenuId(), sysMgmMenu.getMenuSeq());
		this.addOrgUserMgmMenu(app.getAppId(), orgMgmMenu.getMenuId(), orgMgmMenu.getMenuSeq(), orgUserMgmFunc.getFuncId(), orgUserMgmFunc.getFuncUrl());
		this.addGroupMgmMenu(app.getAppId(), orgMgmMenu.getMenuId(), orgMgmMenu.getMenuSeq(), groupMgmFunc.getFuncId(), groupMgmFunc.getFuncUrl());
		
		AcMenu privMgmMenu = this.addPrivMgmMenu(app.getAppId(), sysMgmMenu.getMenuId(), sysMgmMenu.getMenuSeq());
		this.addAppMgmMenu(app.getAppId(), privMgmMenu.getMenuId(), privMgmMenu.getMenuSeq(), appMgmFunc.getFuncId(), appMgmFunc.getFuncUrl());
		this.addMenuMgmMenu(app.getAppId(), privMgmMenu.getMenuId(), privMgmMenu.getMenuSeq(), menuMgmFunc.getFuncId(), menuMgmFunc.getFuncUrl());
		this.addRoleMgmMenu(app.getAppId(), privMgmMenu.getMenuId(), privMgmMenu.getMenuSeq(), roleMgmFunc.getFuncId(), roleMgmFunc.getFuncUrl());
		
		AcMenu otherMgmMenu = this.addOtherMgmMenu(app.getAppId(), sysMgmMenu.getMenuId(), sysMgmMenu.getMenuSeq());
		this.addSysCodeMgmMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), sysCodeMgmFunc.getFuncId(), sysCodeMgmFunc.getFuncUrl());
		this.addWebServerMgmMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), webServerMgmFunc.getFuncId(), webServerMgmFunc.getFuncUrl());
		this.addHomepageMgmMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), homepageMgmFunc.getFuncId(), homepageMgmFunc.getFuncUrl());
		this.addCustomShortcutMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), customShortcutFunc.getFuncId(), customShortcutFunc.getFuncUrl());
		this.addShortcutMgmMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), shortcutMgmFunc.getFuncId(), shortcutMgmFunc.getFuncUrl());
		this.addSysConfigMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), sysConfigFunc.getFuncId(), sysConfigFunc.getFuncUrl());
		this.addSysFileMgmtMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), sysFileFunc.getFuncId(), sysFileFunc.getFuncUrl());
		this.addSystemTraceLogMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), systemTraceLogFunc.getFuncId(), systemTraceLogFunc.getFuncUrl());
		this.addSysLoginLogMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), sysLoginLogFunc.getFuncId(), sysLoginLogFunc.getFuncUrl());
		this.addSysPropAuditLogMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), sysPropAuditLogFunc.getFuncId(), sysPropAuditLogFunc.getFuncUrl());
		this.addRegularWorkTimeMgmtMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), regularWorkTimeMgmtFunc.getFuncId(), regularWorkTimeMgmtFunc.getFuncUrl());
		this.addSpecialTimeMgmtMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), specialTimeMgmtFunc.getFuncId(), specialTimeMgmtFunc.getFuncUrl());
		this.addAosLinkMenu(app.getAppId(), otherMgmMenu.getMenuId(), otherMgmMenu.getMenuSeq(), aosLinkFunc.getFuncId(), aosLinkFunc.getFuncUrl());
	}
	
	/**
	 * 添加系统初始化配置参数
	 */
	private void addSysConfig(){
		SysConfig css = new SysConfig();
		css.setKey(WebContextUtils.SYS_CONFIG_CSS);
		css.setValue("blue");
		css.setMemo("系统界面风格样式");
		sysConfigDao.save(css);
		
		SysConfig homepage = new SysConfig();
		homepage.setKey(WebContextUtils.SYS_CONFIG_HOMEPAGE);
		homepage.setValue("office");
		homepage.setMemo("系统默认首页");
		sysConfigDao.save(homepage);
		
		SysConfig isCluster = new SysConfig();
		isCluster.setKey(WebContextUtils.SYS_CONFIG_IS_CLUSTER);
		isCluster.setValue(OrgConstant.ZERO);
		isCluster.setMemo("是否启用集群（注意：更改此配置项必须重启服务才能生效）");
		sysConfigDao.save(isCluster);
	}
	
	/**
	 * 添加系统管理当前项目应用
	 * @return 应用
	 */
	private AcApplication addLocalApp(){
		AcApplication entity = new AcApplication();
		entity.setAppCode(OrgConstant.LOCAL_APP_FLAG);
		entity.setAppName("系统管理");
		entity.setIsActive(OrgConstant.ONE);
		entity.setAppUrl("/" + OrgConstant.LOCAL_APP_FLAG);
		acApplicationDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加组织管理模块
	 * @param appId 应用ID
	 * @return
	 */
	private AcModule addOrgMgmModule(Long appId){
		AcModule entity = new AcModule();
		entity.setModuleCode("M_OrgMgmt");
		entity.setModuleName("组织管理");
		entity.setAppId(appId);
		entity.setModuleLevel(OrgConstant.NUM_1);
		entity.setIsLeaf(OrgConstant.ZERO);
		entity.setSubCount(2);
		acModuleDao.save(entity);
		
		entity.setModuleSeq("." + entity.getModuleId() + ".");
		acModuleDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加权限管理模块
	 * @param appId 应用ID
	 * @return
	 */
	private AcModule addPrivMgmModule(Long appId){
		AcModule entity = new AcModule();
		entity.setModuleCode("M_PrivMgmt");
		entity.setModuleName("权限管理");
		entity.setAppId(appId);
		entity.setModuleLevel(OrgConstant.NUM_1);
		entity.setIsLeaf(OrgConstant.ZERO);
		entity.setSubCount(3);
		acModuleDao.save(entity);
		
		entity.setModuleSeq("." + entity.getModuleId() + ".");
		acModuleDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加其他管理模块
	 * @param appId 应用ID
	 * @return
	 */
	private AcModule addOtherMgmModule(Long appId){
		AcModule entity = new AcModule();
		entity.setModuleCode("M_OtherMgmt");
		entity.setModuleName("其他管理");
		entity.setAppId(appId);
		entity.setModuleLevel(OrgConstant.NUM_1);
		entity.setIsLeaf(OrgConstant.ZERO);
		entity.setSubCount(6);
		acModuleDao.save(entity);
		
		entity.setModuleSeq("." + entity.getModuleId() + ".");
		acModuleDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加机构管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addOrgUserMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_OrgUserMgmt");
		entity.setFuncName("F_机构用户管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/om-org.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加工作组管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addGroupMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_GroupMgmt");
		entity.setFuncName("F_工作组管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/om-group.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加角色管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addRoleMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_RoleMgmt");
		entity.setFuncName("F_角色管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/ac-role.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加应用功能管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addAppMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_AppMgmt");
		entity.setFuncName("F_应用功能管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/ac-application.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加菜单管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addMenuMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_MenuMgmt");
		entity.setFuncName("F_菜单管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/ac-menu.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加WEB服务器管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addWebServerMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_WebServerMgmt");
		entity.setFuncName("F_WEB服务器管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/ac-server.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加数据字典管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addSysCodeMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_SysCodeMgmt");
		entity.setFuncName("F_数据字典管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/syscode/sys-code.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加数据字典管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addHomepageMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_HomepageMgmt");
		entity.setFuncName("F_系统首页配置管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/at-homepage-config.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加自定义快捷菜单功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addCustomShortcutFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_CustomShortcut");
		entity.setFuncName("F_自定义快捷菜单");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/ac-user-shortcut.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加快捷菜单管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addShortcutMgmFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_ShortcutMgmt");
		entity.setFuncName("F_快捷菜单管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/org/ac-user-shortcut!admin.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加系统初始化设置功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addSysConfigFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_SysConfig");
		entity.setFuncName("F_系统初始化设置");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/sysconfig/sys-config.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加附件管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addSysFileMgmtFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_SysFileMgmt");
		entity.setFuncName("F_附件管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/sysfile/sys-file.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加系统跟踪日志功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addSystemTraceLogFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_SystemTraceLog");
		entity.setFuncName("F_系统跟踪日志");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/syslog/sys-trace-log.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加用户登录日志功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addSysLoginLogFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_SysLoginLog");
		entity.setFuncName("F_用户登录日志");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/syslog/sys-login-log.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加字段审计日志功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addSysPropAuditLogFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_SysPropAuditLog");
		entity.setFuncName("F_字段审计日志");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/syslog/sys-prop-audit-log.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加常规工作时间管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addRegularWorkTimeMgmtFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_RegularWorkTimeMgmt");
		entity.setFuncName("F_常规工作时间管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/workdayholiday/wh-regular-work-time.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加非常规时间管理功能
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addSpecialTimeMgmtFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_SpecialTimeMgmt");
		entity.setFuncName("F_非常规时间管理");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/workdayholiday/wh-special-time.action");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加生成代码链接功能
	 * 注意：须要依赖AOS工具来生成aoslink.jsp文件
	 * @param moduleId 模块ID
	 * @return
	 */
	private AcFunction addAosLinkFunc(Long moduleId){
		AcFunction entity = new AcFunction();
		entity.setFuncCode("F_AosLink");
		entity.setFuncName("F_生成代码链接");
		entity.setModuleId(moduleId);
		entity.setUrlType(OrgConstant.ZERO);
		entity.setFuncUrl("/aoslink.jsp");
		acFunctionDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加系统管理菜单
	 * @param appId 应用ID
	 * @param localAppCode 应用编号
	 * @return
	 */
	private AcMenu addSysMgmMenu(Long appId){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SysMgmt");
		entity.setMenuName("系统管理");
		entity.setMenuLevel(OrgConstant.NUM_1);
		entity.setAppId(appId);
		entity.setIsLeaf(OrgConstant.ZERO);
		entity.setSubCount(3);
		entity.setIsActive(OrgConstant.ONE);
		entity.setSmallImgPath("/resources/images/icons/16_16/cog_edit.png");
		acMenuDao.save(entity);
		
		entity.setMenuSeq("." + entity.getMenuId() + ".");
		acMenuDao.save(entity);
		return entity;
	}
	
	/**
	 * 添加组织管理菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param localAppCode
	 * @return
	 */
	private AcMenu addOrgMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_OrgMgmt");
		entity.setMenuName("组织管理");
		entity.setSortNo(1);
		entity.setSmallImgPath("/resources/images/icons/16_16/chart_organisation.png");
		acMenuDao.save(entity);
		
		initSecondLevelMenu(entity, appId, parentMenuId, parentMenuSeq);
		return entity;
	}
	
	/**
	 * 添加权限管理菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param localAppCode
	 * @return
	 */
	private AcMenu addPrivMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_PrivMgmt");
		entity.setMenuName("权限管理");
		entity.setSortNo(2);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_group.png");
		acMenuDao.save(entity);
		
		initSecondLevelMenu(entity, appId, parentMenuId, parentMenuSeq);
		return entity;
	}
	
	/**
	 * 添加其他管理菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param localAppCode
	 * @return
	 */
	private AcMenu addOtherMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_OtherMgmt");
		entity.setMenuName("其他管理");
		entity.setSortNo(3);
		entity.setSmallImgPath("/resources/images/icons/16_16/wrench.png");
		acMenuDao.save(entity);
		
		initSecondLevelMenu(entity, appId, parentMenuId, parentMenuSeq);
		return entity;
	}
	
	/**
	 * 添加机构用户管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addOrgUserMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_OrgUserMgmt");
		entity.setMenuName("机构用户管理");
		entity.setSortNo(1);
		entity.setSmallImgPath("/resources/images/icons/16_16/chart_organisation.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加机构用户管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private Long addGroupMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_GroupMgmt");
		entity.setMenuName("工作组管理");
		entity.setSortNo(2);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_group.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
		return entity.getMenuId();
	}
	
	/**
	 * 添加应用功能管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addAppMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_AppMgmt");
		entity.setMenuName("应用功能管理");
		entity.setSortNo(1);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_form_edit.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加角色管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addRoleMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_RoleMgmt");
		entity.setMenuName("角色管理");
		entity.setSortNo(3);
		entity.setSmallImgPath("/resources/images/icons/16_16/folder_user.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加菜单管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addMenuMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_MenuMgmt");
		entity.setMenuName("菜单管理");
		entity.setSortNo(2);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_side_boxes.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加数据字典管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addSysCodeMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SysCodeMgmt");
		entity.setMenuName("数据字典管理");
		entity.setSortNo(1);
		entity.setSmallImgPath("/resources/images/icons/16_16/report.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加系统首页配置管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addHomepageMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_HomepageMgmt");
		entity.setMenuName("系统首页配置管理");
		entity.setSortNo(3);
		entity.setSmallImgPath("/resources/images/icons/16_16/house_link.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加自定义快捷菜单的菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addCustomShortcutMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_CustomShortcut");
		entity.setMenuName("自定义快捷菜单");
		entity.setSortNo(4);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_sideEXpand.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加快捷菜单管理的菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addShortcutMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_ShortcutMgmt");
		entity.setMenuName("快捷菜单管理");
		entity.setSortNo(5);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加系统初始化设置的菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addSysConfigMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SysConfig");
		entity.setMenuName("系统初始化设置");
		entity.setSortNo(6);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加附件管理的菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addSysFileMgmtMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SysFileMgmt");
		entity.setMenuName("附件管理");
		entity.setSortNo(7);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加系统跟踪日志的菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addSystemTraceLogMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SystemTraceLog");
		entity.setMenuName("系统跟踪日志");
		entity.setSortNo(8);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加用户登录日志的菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addSysLoginLogMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SysLoginLog");
		entity.setMenuName("用户登录日志");
		entity.setSortNo(9);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加字段审计日志的菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addSysPropAuditLogMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SysPropAuditLog");
		entity.setMenuName("字段审计日志");
		entity.setSortNo(10);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加常规工作时间管理的菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addRegularWorkTimeMgmtMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_RegularWorkTimeMgmt");
		entity.setMenuName("常规工作时间管理");
		entity.setSortNo(11);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加非常规时间管理的菜单
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addSpecialTimeMgmtMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_SpecialTimeMgmt");
		entity.setMenuName("非常规时间管理");
		entity.setSortNo(12);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_view_detail.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 生成AOS代码自动生成的链接页面
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void addAosLinkMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_AosLink");
		entity.setMenuName("生成代码链接");
		entity.setSortNo(6);
		entity.setSmallImgPath("/resources/images/icons/16_16/disconnect.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加WEB服务器管理菜单
	 * @param appId
	 * @param localAppCode
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcUrl
	 * @return
	 */
	private void addWebServerMgmMenu(Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		AcMenu entity = new AcMenu();
		entity.setMenuCode("ME_WebServerMgmt");
		entity.setMenuName("WEB服务器管理");
		entity.setSortNo(2);
		entity.setSmallImgPath("/resources/images/icons/16_16/application_xp_terminal.png");
		acMenuDao.save(entity);
		
		initLeafMenu(entity, appId, parentMenuId, parentMenuSeq, funcId, funcUrl);
	}
	
	/**
	 * 添加生成代码链接菜单
	 * @param entity
	 * @param appId
	 * @param parentMenuId
	 * @param parentMenuSeq
	 * @param funcId
	 * @param funcUrl
	 */
	private void initLeafMenu(AcMenu entity, Long appId, Long parentMenuId, String parentMenuSeq, Long funcId, String funcUrl){
		entity.setMenuLevel(3);
		entity.setAppId(appId);
		entity.setParentMenuId(parentMenuId);
		entity.setFuncId(funcId);
		entity.setMenuUrl("/" + OrgConstant.LOCAL_APP_FLAG + funcUrl);
		entity.setIsLeaf(OrgConstant.ONE);
		entity.setSubCount(0);
		entity.setIsActive(OrgConstant.ONE);
		entity.setMenuSeq(parentMenuSeq + entity.getMenuId() + ".");
		acMenuDao.save(entity);
	}
	
	private void initSecondLevelMenu(AcMenu entity, Long appId, Long parentMenuId, String parentMenuSeq){
		entity.setMenuLevel(2);
		entity.setAppId(appId);
		entity.setParentMenuId(parentMenuId);
		entity.setIsLeaf(OrgConstant.ZERO);
		entity.setSubCount(2);
		entity.setIsActive(OrgConstant.ONE);
		entity.setMenuSeq(parentMenuSeq + entity.getMenuId() + ".");
		acMenuDao.save(entity);
	}
	
	/**
	 * 添加系统管理员用户
	 * @param aosAdminPassword 系统管理员密码
	 * @return 用户ID
	 */
	private Long addAosAdminUser(String aosAdminPassword){
		OmUser entity = new OmUser();
		entity.setLoginName(OrgConstant.ROLE_ADMIN_CODE);
		entity.setPassword(aosAdminPassword);
		entity.setUserCode(OrgConstant.ROLE_ADMIN_CODE);
		entity.setUserName(OrgConstant.ROLE_ADMIN_NAME);
		entity.setIsActive(OrgConstant.ONE);
		omUserDao.save(entity);
		return entity.getUserId();
	}
	
	/**
	 * 添加系统管理员角色
	 * @return 角色ID
	 */
	private Long addAosAdminRole(){
		AcRole entity = new AcRole();
		entity.setRoleCode(OrgConstant.ROLE_ADMIN_CODE);
		entity.setRoleName(OrgConstant.ROLE_ADMIN_NAME);
		entity.setRoleType("系统级");
		acRoleDao.save(entity);
		return entity.getRoleId();
	}
	
	/**
	 * 添加用户与角色关联
	 * @param userId
	 * @param roleId
	 */
	private void addUserRole(Long userId, Long roleId){
		AcUserRole entity = new AcUserRole();
		entity.setUserId(userId);
		entity.setRoleId(roleId);
		acUserRoleDao.save(entity);
	}
	
	/**
	 * 添加角色与功能关联
	 * @param roleId
	 * @param funcId
	 * @param moduleId
	 * @param appId
	 */
	private void addRoleFunc(Long roleId, Long funcId, Long moduleId, Long appId){
		AcRoleFunc entity = new AcRoleFunc();
		entity.setRoleId(roleId);
		entity.setFuncId(funcId);
		entity.setModuleId(moduleId);
		entity.setAppId(appId);
		acRoleFuncDao.save(entity);
	}
	
	/**
	 * 添加若干系统首页配置信息
	 */
	private void addHomepageConfig(){
		AtHomepageConfig h1 = new AtHomepageConfig();
		h1.setHomepageCode("office");
		h1.setHomepageName("Office风格首页");
		h1.setLoadMenuLevel(OrgConstant.NUM_1);
		h1.setLoadByTree(OrgConstant.ZERO);
		h1.setModelName(ExtStoreMenu.class.getSimpleName());
		h1.setIsActive(OrgConstant.ONE);
		atHomepageConfigDao.save(h1);
		
		AtHomepageConfig h3 = new AtHomepageConfig();
		h3.setHomepageCode("tree");
		h3.setHomepageName("树菜单首页");
		h3.setLoadMenuLevel(OrgConstant.NUM_0);
		h3.setLoadByTree(OrgConstant.ZERO);
		h3.setModelName(LinkTreeNode.class.getSimpleName());
		h3.setIsActive(OrgConstant.ONE);
		atHomepageConfigDao.save(h3);
		
		AtHomepageConfig h4 = new AtHomepageConfig();
		h4.setHomepageCode("menuaccordion");
		h4.setHomepageName("菜单+折叠首页");
		h4.setLoadMenuLevel(OrgConstant.NUM_1);
		h4.setLoadByTree(OrgConstant.ZERO);
		h4.setModelName(ExtElement.class.getSimpleName());
		h4.setIsActive(OrgConstant.ONE);
		atHomepageConfigDao.save(h4);
		
		AtHomepageConfig h5 = new AtHomepageConfig();
		h5.setHomepageCode("menutree");
		h5.setHomepageName("菜单+树首页");
		h5.setLoadMenuLevel(OrgConstant.NUM_1);
		h5.setLoadByTree(OrgConstant.ZERO);
		h5.setModelName(LinkTreeNode.class.getSimpleName());
		h5.setIsActive(OrgConstant.ONE);
		atHomepageConfigDao.save(h5);
		
		AtHomepageConfig h6 = new AtHomepageConfig();
		h6.setHomepageCode("treetab");
		h6.setHomepageName("树+Tab首页");
		h6.setLoadMenuLevel(OrgConstant.NUM_0);
		h6.setLoadByTree(OrgConstant.ZERO);
		h6.setModelName(LinkTreeNode.class.getSimpleName());
		h6.setIsActive(OrgConstant.ONE);
		atHomepageConfigDao.save(h6);
	}
	
	/**
	 * 添加必要的数据字典项
	 */
	private void addSysCode(){
		addUserPosition();
		addRoleType();
		addPosStatus();
		addPageOpenMode();
		addOrgType();
		addOrgStatus();
		addOrgDegree();
		addOrgArea();
		addModuleType();
		addFunctionType();
		addAppType();
		addSysConfigCss();
	}
	
	/**
	 * 添加在岗情况数据字典
	 */
	private void addUserPosition(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_USER_POSITION");
		type.setName("在岗情况");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_USER_POSITION");
		item1.setCode("leave");
		item1.setName("离职");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(2);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_USER_POSITION");
		item2.setCode("on");
		item2.setName("在职");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(1);
		sysCodeItemDao.save(item2);
	}
	
	/**
	 * 添加角色类型数据字典
	 */
	private void addRoleType(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_ROLE_TYPE");
		type.setName("角色类型");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_ROLE_TYPE");
		item1.setCode("系统级");
		item1.setName("系统级");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
	}
	
	/**
	 * 添加岗位状态数据字典
	 */
	private void addPosStatus(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_POS_STATUS");
		type.setName("岗位状态");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_POS_STATUS");
		item1.setCode("running");
		item1.setName("正常");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_POS_STATUS");
		item2.setCode("cancel");
		item2.setName("注销");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
	}
	
	/**
	 * 添加页面打开方式数据字典
	 */
	private void addPageOpenMode(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_PAGE_OPEN_MODE");
		type.setName("页面打开方式");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_PAGE_OPEN_MODE");
		item1.setCode("comm");
		item1.setName("普通页面");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
	}
	
	/**
	 * 添加机构类型数据字典
	 */
	private void addOrgType(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_ORG_TYPE");
		type.setName("机构类型");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_ORG_TYPE");
		item1.setCode("h");
		item1.setName("总公司");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_ORG_TYPE");
		item2.setCode("hd");
		item2.setName("总公司部门");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
		
		SysCodeItem item3 = new SysCodeItem();
		item3.setTypeCode("AOS_ORG_TYPE");
		item3.setCode("b");
		item3.setName("分公司");
		item3.setStatus(OrgConstant.NUM_1);
		item3.setSortno(3);
		sysCodeItemDao.save(item3);
		
		SysCodeItem item4 = new SysCodeItem();
		item4.setTypeCode("AOS_ORG_TYPE");
		item4.setCode("bd");
		item4.setName("分公司部门");
		item4.setStatus(OrgConstant.NUM_1);
		item4.setSortno(4);
		sysCodeItemDao.save(item4);
	}
	
	/**
	 * 添加机构状态数据字典
	 */
	private void addOrgStatus(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_ORG_STATUS");
		type.setName("机构状态");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_ORG_STATUS");
		item1.setCode("running");
		item1.setName("正常");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_ORG_STATUS");
		item2.setCode("cancel");
		item2.setName("注销");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
	}
	
	/**
	 * 添加机构等级数据字典
	 */
	private void addOrgDegree(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_ORG_DEGREE");
		type.setName("机构等级");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_ORG_DEGREE");
		item1.setCode("1");
		item1.setName("一级");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_ORG_DEGREE");
		item2.setCode("2");
		item2.setName("二级");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
		
		SysCodeItem item3 = new SysCodeItem();
		item3.setTypeCode("AOS_ORG_DEGREE");
		item3.setCode("3");
		item3.setName("三级");
		item3.setStatus(OrgConstant.NUM_1);
		item3.setSortno(3);
		sysCodeItemDao.save(item3);
		
		SysCodeItem item4 = new SysCodeItem();
		item4.setTypeCode("AOS_ORG_DEGREE");
		item4.setCode("4");
		item4.setName("四级");
		item4.setStatus(OrgConstant.NUM_1);
		item4.setSortno(4);
		sysCodeItemDao.save(item4);
	}
	
	/**
	 * 添加机构地域数据字典
	 */
	private void addOrgArea(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_ORG_AREA");
		type.setName("机构地域");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_ORG_AREA");
		item1.setCode("gz");
		item1.setName("广州");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_ORG_AREA");
		item2.setCode("bj");
		item2.setName("北京");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
	}
	
	/**
	 * 添加模块类型数据字典
	 */
	private void addModuleType(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_MODULE_TYPE");
		type.setName("模块类型");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_MODULE_TYPE");
		item1.setCode("1");
		item1.setName("平台组件");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_MODULE_TYPE");
		item2.setCode("2");
		item2.setName("业务模块");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
	}
	
	/**
	 * 添加功能类型数据字典
	 */
	private void addFunctionType(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_FUNCTION_TYPE");
		type.setName("功能类型");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_FUNCTION_TYPE");
		item1.setCode("1");
		item1.setName("核心功能");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_FUNCTION_TYPE");
		item2.setCode("2");
		item2.setName("辅助模块");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
	}
	
	/**
	 * 添加应用类型数据字典
	 */
	private void addAppType(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_APP_TYPE");
		type.setName("应用类型");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_APP_TYPE");
		item1.setCode("1");
		item1.setName("本地");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(1);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_APP_TYPE");
		item2.setCode("2");
		item2.setName("远程");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(2);
		sysCodeItemDao.save(item2);
	}
	
	/**
	 * 添加系统首页风格样式
	 */
	private void addSysConfigCss(){
		SysCodeType type = new SysCodeType();
		type.setCode("AOS_SYSCONFIG_CSS");
		type.setName("系统首页风格样式");
		type.setGrade(OrgConstant.ONE);
		sysCodeTypeDao.save(type);
		
		SysCodeItem item1 = new SysCodeItem();
		item1.setTypeCode("AOS_SYSCONFIG_CSS");
		item1.setCode("blue");
		item1.setName("blue");
		item1.setStatus(OrgConstant.NUM_1);
		item1.setSortno(0);
		sysCodeItemDao.save(item1);
		
		SysCodeItem item2 = new SysCodeItem();
		item2.setTypeCode("AOS_SYSCONFIG_CSS");
		item2.setCode("gray");
		item2.setName("gray");
		item2.setStatus(OrgConstant.NUM_1);
		item2.setSortno(1);
		sysCodeItemDao.save(item2);
	}
}
